package cn.abcsys.cloud.devops.web.controller;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.abcsys.cloud.devops.web.entity.ClusterEnv;
import cn.abcsys.cloud.devops.web.entity.User;
import cn.abcsys.cloud.devops.web.service.ClusterEnvService;
import cn.abcsys.cloud.devops.web.util.Result;

@Controller
@RequestMapping(value="/clusterEnv")
public class ClusterEnvController {
	private static final Logger LOGGER = Logger.getLogger(ClusterEnvController.class);
	@Resource
	private ClusterEnvService clusterEnvService;
	/**
	 * @param clusterEnv
	 * @return
	 */
	@RequestMapping(value="/add",method={RequestMethod.POST})
	@ResponseBody
	public Result addCluserEnv(@RequestBody ClusterEnv clusterEnv){
		if(null == clusterEnv)
			return new Result(false, "选择数据为空");
		return clusterEnvService.createCLusterEnv(clusterEnv);
	}
	
	/**根据当前环境查询集群Ip
	 * @param request
	 * @param map
	 * @return
	 */
	@RequestMapping(value="/getClusterByEnvId",method={RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public Result getClusterByEnvId(HttpServletRequest request){
		//if(null == map.get("envId"))
		if(null == (User) request.getSession().getAttribute("user"))
			return new Result(false, "会话失效");
		Integer envId = (Integer) request.getSession().getAttribute("envId");
		LOGGER.info("环境Id=====>>"+envId);
		return clusterEnvService.getrClusterByEnvId(envId);
	}
}
